$(window).load(function(){
			 
				//global vars
				var form = $("#frmVehicle");
				var name = $("#txtStockNumber");
				var nameInfo = $("#nameInfo");
				
				//On blur
				name.blur(validateName);
				
				//On key press
				name.keyup(validateName);
				
				
				//validation functions
				
				function validateName(){
					//if it's NOT valid
					if(name.val().length < 1){
						name.removeClass("tb7");
						name.addClass("errortxt");
						nameInfo.text("Stock Number is Required!");
						nameInfo.css('display', 'block');
						nameInfo.addClass("errorlbl");
						return false;
					}
					//if it's valid
					else{
						name.removeClass("errortxt");
						name.addClass("tb7");
						nameInfo.css('display', 'none');
						nameInfo.text("Stock Number is Required!");
						nameInfo.removeClass("errorlbl");
						return true;
					}
				}
			 
				$("#tabs").tabs({

					select: function(event, ui) {
						var valid = true;
						var current = $(this).tabs("option", "selected");
						var panelId = $("#tabs ul a").eq(current).attr("href");

						if(ui.index > current)
						{
							$(panelId).find("input").each(function() {
								//console.log(valid);
								if (validateName() && valid) {
									valid = true;
								}
								else
								{
									valid = false;
								}

								
							});

						}

						return valid;
					}   

				});
				
				$("#btnBasicData").click(function() {
				if(validateName())
				{
					var vehicleStatus = $("input[@name='VehicleStatus']:checked").val();
					var txtyear  = $("#txtyear").val();
					var txtmake = $("#txtmake").val();
					var txtmodel = $("#txtmodel").val();
					var txtStockNumber = $("#txtStockNumber").val();
					var txtExColor =  $("#txtExColor").val();
					var txtMilage = $("#txtMilage").val();
					var txtdoors = $("#txtdoors").val();
					var txtbPassengers =  $("#txtbPassengers").val();
					var txtbKM =  $("#txtbKM").val();
					var txtbFuel =  $("#txtbFuel").val();
					var txtbEngine =  $("#txtbEngine").val();
					var txtbInterior =  $("#txtbInterior").val();
					var txtOwners = $("#txtOwners").val();
					var txtMPG = $("#txtMPG").val();
					
					 $.post("../common-save-functions.php",{txtMPG:txtMPG,txtOwners:txtOwners,txtMilage:txtMilage,vehicleStatus:vehicleStatus,txtyear:txtyear,txtmake:txtmake,txtmodel:txtmodel,txtStockNumber:txtStockNumber,txtExColor:txtExColor,txtdoors:txtdoors,txtbPassengers:txtbPassengers,txtbKM:txtbKM,txtbFuel:txtbFuel,txtbEngine:txtbEngine,txtbInterior:txtbInterior,action:"basicdata"},
					 function(data)
					 {  	
						 $("#tabs").tabs("select", 1);
						
					 },"text");
					
					return true;					
				}
				else
				{
					return false;
				}
					
				});				
				
				$("#btnPrice").click(function() {
					
					var txtStockNumber = $("#txtStockNumber").val();
					var txtoriginalprice = $("#txtoriginalprice").val();
					var txtofferedprice = $("#txtofferedprice").val();
					var txtfprice = $("#txtfprice").val();
					//alert(txtStockNumber+"---"+txtoriginalprice+"---"+txtofferedprice+"---"+txtfprice);
					$.post("../common-save-functions.php",{action:"pricedata",txtStockNumber:txtStockNumber,txtoriginalprice:txtoriginalprice,txtofferedprice:txtofferedprice,txtfprice:txtfprice},
					function (data)
					{
						$("#tabs").tabs("select", 3);
					},"text");
					
				});
				
				$("#btnMOT").click(function() {
					
					var txtStockNumber = $("#txtStockNumber").val();
					var txtMotMonths = $("#txtMotMonths").val();
					var txtRoadTaxMonths = $("#txtRoadTaxMonths").val();
					var txtRoadTaxPrice = $("#txtRoadTaxPrice").val();
					var txtServiceHistory = $("#txtServiceHistory").val();
					var txtMotHistory = $("#txtMotHistory").val();
					var txtFinanceOption = $("#txtFinanceOption").val();
					var txtWarranty = $("#txtWarranty").val();
					var txtCondition = $("#txtCondition").val();
					$.post("../common-save-functions.php",{action:"financedata",txtStockNumber:txtStockNumber, txtMotMonths:txtMotMonths,txtRoadTaxMonths:txtRoadTaxMonths,txtRoadTaxPrice:txtRoadTaxPrice,txtServiceHistory:txtServiceHistory,txtMotHistory:txtMotHistory,txtFinanceOption:txtFinanceOption,txtWarranty:txtWarranty, txtCondition: txtCondition},
							function (data)
							{
								$("#tabs").tabs("select", 4);
							},"text");
							
				});
				
				$("#btnExteriorFeatures").click(function() {
					
					var txtStockNumber = $("#txtStockNumber").val();
					var txtOptionsExFeatures = tinyMCE.get("txtOptionsExFeatures").getContent();
					alert(txtOptionsExFeatures);
					$.post("../common-save-functions.php",{action:"additionaldata",txtStockNumber:txtStockNumber, txtOptionsExFeatures:txtOptionsExFeatures},
							function (data)
							{
								alert("All Data Successfully Saved.");
							},"text");
				});
				
				
				$("#btnVehicleUpload").click(function() {
					$("#tabs").tabs("select", 2);
				});
				
				
			});

